/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package datos;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Ing. Monica Merlo, Ing. Agustin  Fernandez
 */
@Entity
@Table(name = "foto")
@NamedQueries({@NamedQuery(name = "Foto.findAll", query = "SELECT f FROM Foto f"), 
               @NamedQuery(name = "Foto.findById", query = "SELECT f FROM Foto f WHERE f.id = :id"),
               @NamedQuery(name = "Foto.findByFecha", query = "SELECT f FROM Foto f WHERE f.fecha = :fecha"),
               @NamedQuery(name = "Foto.findByIdObraFotos", query = "SELECT f FROM Foto f WHERE f.idObra.id = :idObra AND f.idObra.eliminada = 0"),
               @NamedQuery(name = "Foto.encontrarNFotosObra", query = "SELECT f FROM Foto f WHERE f.idObra.id = :idObra AND f.idObra.eliminada = 0 ORDER BY f.fecha DESC")})
public class Foto implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Lob
    @Column(name = "ruta")
    private String ruta;
    @Basic(optional = false)
    @Lob
    @Column(name = "rutaThumbnail")
    private String rutaThumbnail;
    @Basic(optional = false)
    @Column(name = "fecha")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecha;
    @Lob
    @Column(name = "descripcion")
    private String descripcion;
    @JoinColumn(name = "idObra", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Obra idObra;

    public Foto() {
    }

    public Foto(Integer id) {
        this.id = id;
    }

    public Foto(Integer id, String ruta, String rutaThumbnail, Date fecha) {
        this.id = id;
        this.ruta = ruta;
        this.rutaThumbnail = rutaThumbnail;
        this.fecha = fecha;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getRuta() {
        return ruta;
    }

    public void setRuta(String ruta) {
        this.ruta = ruta;
    }

    public String getRutaThumbnail() {
        return rutaThumbnail;
    }

    public void setRutaThumbnail(String rutaThumbnail) {
        this.rutaThumbnail = rutaThumbnail;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public Obra getIdObra() {
        return idObra;
    }

    public void setIdObra(Obra idObra) {
        this.idObra = idObra;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Foto)) {
            return false;
        }
        Foto other = (Foto) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "datos.Foto[id=" + id + "]";
    }

}
